<!--
 * @Author: wuyuanhong wuyuanhong@szhbzc.com
 * @Date: 2024-09-11 17:45:18
 * @LastEditors: wuyuanhong wuyuanhong@szhbzc.com
 * @LastEditTime: 2024-09-14 17:59:27
 * @FilePath: \xiamenAgency\src\view\menu\basicInformation\basicData\cuisineManagement\components\dishReview.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <cus-drawer ref="cusDrawerRef" title="食谱信息导入预览" @onClose="onClose" :maskClosable="false">
        <Form ref="dishFormValidate" :model="dishSearchForm" inline :label-width="80" @keydown.native.enter.prevent="onInit"
            class="dishFormBox">
            <FormItem label="菜肴名称" prop="dishName">
                <Input v-model="dishSearchForm.dishName" maxlength="20" clearable placeholder="请输入菜肴名称"
                    style="width: 200px">
                </Input>
            </FormItem>
            <FormItem label="相似状态" prop="similarStatus">
                <Select v-model="dishSearchForm.similarStatus" style="width: 200px" placeholder="请选择相似状态">
                    <Option :value="item.value" v-for="item in similarOptions" :key="item.value">{{ item.label }}</Option>
                </Select>
            </FormItem>
            <cusButton class="ml_20" type="primary" @onClick="onInit">查询</cusButton>
            <cusButton class="ml_20" type="warning" @onClick="confirmImport">确认</cusButton>
        </Form>
        <div style="display: flex;">
            <cusButton v-if="!openSelect" style="color:#0052D9;" type="text" @onClick="onOpenSelect">选择</cusButton>
            <cusButton v-if="openSelect" style="color:#E6A23C;" type="text" @onClick="onOpenSelect">关闭</cusButton>
            <cusButton v-if="selectInventory.length" style="color:#F56C6C;" type="text" @onClick="selectDeleteDish">删除
            </cusButton>
        </div>
        <cus-modal ref="cusModalRef" title="删除菜肴" :width="500" @onOk="onConfrim">
            <Icon type="ios-alert-outline" :size="16" color="#cb0000" style="margin-right:5px" />
            <span>此操作不可逆,确定要进行删除吗?</span>
        </cus-modal>
        <cus-table border :height="700" :loading="dishSearchForm.searchLoading" :columns="dishReviewColumns"
            :data="dishReviewData" @on-selection-change="changeSelect" @on-select-all="changeSelectAll"
            @on-select-all-cancel="changeSelectAllCancel" @on-select-cancel="onSelectCancel" ref="cusTableRef">
            <template slot-scope="{ row, index }" slot="dishName">
                {{ row.dishName }}
            </template>
            <template slot-scope="{ row, index }" slot="weekTimesValue">
                {{ row.weekTimesValue }}
            </template>
            <template slot-scope="{ row, index }" slot="mealTimesValue">
                {{ row.mealTimesValue }}
            </template>
            <template slot-scope="{ row, index }" slot="errReason">
                <div v-for="items in row.dishReviewDetailEntityList" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div class="disabledCol errReasonBox">
                        <Tooltip :max-width="800" :content="items.errReason" placement="top-start">
                            {{ items.errReason }}
                        </Tooltip>
                    </div>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="similarDishName">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div class="disabledCol"> {{ items.similarDishName }}</div>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="similar">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div class="disabledCol"> {{ items.similar }}</div>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="dishClass">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.dishClass }}
                    </div>
                    <Select v-else v-model="items.dishClass" placeholder="请选择菜肴类型" style="width: 150px">
                        <Option v-for="dishItem in dishSelectData.dishTypeData" :key="dishItem.id"
                            :label="dishItem.dishCategory" :value="dishItem.dishCategory" />
                    </Select>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="newType">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.newType }}
                    </div>
                    <Select v-else v-model="items.newType" placeholder="请选择菜肴类别" style="width: 150px">
                        <Option v-for="dishItem in dishSelectData.dishSpecialtyData" :key="dishItem.id"
                            :label="dishItem.name" :value="dishItem.name" />
                    </Select>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="nurTarget">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.nurTarget }}
                    </div>
                    <Select v-else v-model="items.nurTarget" placeholder="请选择营养标签" style="width: 150px">
                        <Option v-for="dishItem in dishSelectData.dishTargetData" :key="dishItem.id"
                            :label="dishItem.targetName" :value="dishItem.targetName" />
                    </Select>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="skill">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.skill }}
                    </div>
                    <Select v-else v-model="items.skill" placeholder="请选择技法" style="width: 150px">
                        <Option v-for="dishItem in dishSelectData.dishSkillData" :key="dishItem.id" :label="dishItem.value"
                            :value="dishItem.value" />
                    </Select>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="taste">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.taste }}
                    </div>
                    <Select v-else v-model="items.taste" placeholder="请选择口味" style="width: 150px">
                        <Option v-for="dishItem in dishSelectData.dishTasteData" :key="dishItem.id" :label="dishItem.value"
                            :value="dishItem.value" />
                    </Select>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="materialName1">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.materialName1 }}
                    </div>
                    <Input v-else v-model="items.materialName1" clearable style="width: 150px"></Input>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="materialWeight1">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.materialWeight1 }}
                    </div>
                    <InputNumber v-else :min="0" :precision="2" v-model="items.materialWeight1" :active-change="false">
                    </InputNumber>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="materialName2">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.materialName2 }}
                    </div>
                    <Input v-else v-model="items.materialName2" clearable style="width: 150px"></Input>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="materialWeight2">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.materialWeight2 }}
                    </div>
                    <InputNumber v-else :min="0" :precision="2" v-model="items.materialWeight2" :active-change="false">
                    </InputNumber>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="materialName3">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.materialName3 }}
                    </div>
                    <Input v-else v-model="items.materialName3" clearable style="width: 150px"></Input>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="materialWeight3">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.materialWeight3 }}
                    </div>
                    <InputNumber v-else :min="0" :precision="2" v-model="items.materialWeight3" :active-change="false">
                    </InputNumber>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="materialName4">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.materialName4 }}
                    </div>
                    <Input v-else v-model="items.materialName4" clearable style="width: 150px"></Input>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="materialWeight4">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.materialWeight4 }}
                    </div>
                    <InputNumber v-else :min="0" :precision="2" v-model="items.materialWeight4" :active-change="false">
                    </InputNumber>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="materialName5">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.materialName5 }}
                    </div>
                    <Input v-else v-model="items.materialName5" clearable style="width: 150px"></Input>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="materialWeight5">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.materialWeight5 }}
                    </div>
                    <InputNumber v-else :min="0" :precision="2" v-model="items.materialWeight5" :active-change="false">
                    </InputNumber>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="materialName6">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.materialName6 }}
                    </div>
                    <Input v-else v-model="items.materialName6" clearable style="width: 150px"></Input>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="materialWeight6">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.materialWeight6 }}
                    </div>
                    <InputNumber v-else :min="0" :precision="2" v-model="items.materialWeight6" :active-change="false">
                    </InputNumber>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="cookingProcess">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.cookingProcess }}
                    </div>
                    <Input v-else v-model="items.cookingProcess" clearable style="width: 150px"></Input>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="cutWithProcess">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.cutWithProcess }}
                    </div>
                    <Input v-else v-model="items.cutWithProcess" clearable style="width: 150px"></Input>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="curingRate">
                <div v-for="items in row.mealImportReviewDetailEntities" :key="items.id" class="colStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }">
                    <div v-if="!items.edit">
                        {{ items.curingRate }}
                    </div>
                    <Input v-else v-model="items.curingRate" clearable style="width: 150px"></Input>
                </div>
            </template>
            <template slot-scope="{ row, index }" slot="operation">
                <div v-for="(items, detailIndex) in row.mealImportReviewDetailEntities" :key="items.id" class="colOperStyle"
                    :style="{ height: !items.edit ? '48px' : '57px' }" :class="items.edit ? 'editOperStyle' : ''">
                    <cusButton v-if="items.used" :style="{ color: '#67C23A', padding: '0 8px' }" size="small" type="text">
                        已选择
                    </cusButton>
                    <Poptip v-else transfer confirm width="250" ok-text="确认" cancel-text="取消" :title="`确认选择该项作为匹配菜肴吗?`"
                        @on-ok="selectDishReview(items.id, row.mealImportReviewDetailEntities)">
                        <cusButton :style="{ color: '#0052D9', padding: '0 8px' }" size="small" type="text">选择</cusButton>
                    </Poptip>
                    <cusButton v-if="items.edit" :style="{ color: '#0052D9', padding: '0 8px' }" size="small" type="text"
                        @onClick="saveDishReview(items, detailIndex, index)">保存
                    </cusButton>
                    <cusButton v-if="items.edit" :style="{ color: '#909399', padding: '0 8px' }" size="small" type="text"
                        @onClick="cancelDishReview(items, detailIndex, index)">取消
                    </cusButton>
                    <cusButton v-if="!items.edit" :style="{ color: '#0052D9', padding: '0 8px' }" size="small" type="text"
                        @onClick="editDishReview(detailIndex, index)">编辑
                    </cusButton>
                    <Poptip confirm transfer placement="left" width="250" ok-text="确认" cancel-text="取消" :title="`确认删除该项吗?`"
                        @on-ok="deleteDishReview(items.id, row)">
                        <cusButton :style="{ color: '#F56C6C', padding: '0 8px' }" size="small" type="text">
                            删除
                        </cusButton>
                    </Poptip>
                </div>
            </template>
        </cus-table>
        <div style="width: 100%; display: flex; justify-content: flex-end">
            <cus-page :data="pageInit" class="mt_20" @pageChange="dishReviewSearch()"></cus-page>
        </div>
    </cus-drawer>
</template>
<script>
import {
    mealReviewPage, mealReviewEdit, mealReviewSelect, mealReviewDeleteDetail, mealReviewDelete, examineMealReviewData,
    returnMealPlanData, dishTypeSpecialty, dishTarget, getDishListType, getDishAttributeValue,
} from "@/api/business/dishesModule";
export default {
    data() {
        return {
            similarOptions: [
                {
                    label: '未匹配',
                    value: 0,
                },
                {
                    label: '已匹配',
                    value: 1,
                },
                {
                    label: '全部',
                    value: -1,
                },
            ],
            // 查询条件
            dishSearchForm: {
                dishName: '',    //菜肴名称
                similarStatus: -1,  //相似状态
                searchLoading: false,
            },
            // 分页配置
            pageInit: {
                page: 1,
                pageSize: 20,
                pageTotal: 0,
            },
            //获取所属选择框的选项值 
            dishSelectData: {
                dishTargetData: [],
                dishTypeData: [],
                dishSpecialtyData: [],
                dishSkillData: [],
                dishTasteData: [],
            },
            // 菜肴表格数据
            dishReviewData: [],
            dishReviewDataCopy: [],
            // 菜肴表格列
            dishReviewColumns: [
                { title: "序号", width: 70, type: "index", align: "center", },
                { title: "星期", slot: "weekTimesValue", width: 100, align: 'center' },
                { title: "餐食", slot: "mealTimesValue", width: 100, align: 'center' },
                { title: "菜肴名称", slot: "dishName", width: 150, align: 'center' },
                { title: "错误原因", slot: "errReason", width: 150, align: 'center' },
                { title: "匹配菜肴", slot: "similarDishName", width: 150, align: 'center' },
                { title: "相似度", slot: "similar", width: 150, align: 'center' },
                { title: "菜肴类型", slot: "dishClass", width: 175, align: 'center' },
                { title: "原料1", slot: "materialName1", width: 175, align: 'center' },
                { title: "下料量1", slot: "materialWeight1", width: 175, align: 'center' },
                { title: "原料2", slot: "materialName2", width: 175, align: 'center' },
                { title: "下料量2", slot: "materialWeight2", width: 175, align: 'center' },
                { title: "原料3", slot: "materialName3", width: 175, align: 'center' },
                { title: "下料量3", slot: "materialWeight3", width: 175, align: 'center' },
                { title: "原料4", slot: "materialName4", width: 175, align: 'center' },
                { title: "下料量4", slot: "materialWeight4", width: 175, align: 'center' },
                { title: "原料5", slot: "materialName5", width: 175, align: 'center' },
                { title: "下料量5", slot: "materialWeight5", width: 175, align: 'center' },
                { title: "原料6", slot: "materialName6", width: 175, align: 'center' },
                { title: "下料量6", slot: "materialWeight6", width: 175, align: 'center' },
                { title: "菜肴类别", slot: "newType", width: 175, align: 'center' },
                { title: "营养标签", slot: "nurTarget", width: 175, align: 'center' },
                { title: "技法", slot: "skill", width: 175, align: 'center' },
                { title: "口味", slot: "taste", width: 175, align: 'center' },
                { title: "烹饪工艺", slot: "cookingProcess", width: 175, align: 'center' },
                { title: "切配工艺", slot: "cutWithProcess", width: 175, align: 'center' },
                { title: "生熟比", slot: "curingRate", width: 175, align: 'center' },
                { title: "操作", slot: "operation", fixed: 'right', width: 200, align: 'center' },
            ],
            // 是否打开选择
            openSelect: false,
            // 选中的数据
            selectionList: [],
            selectInventory: [],
            cancelAllSelect: [], //取消全选
        };
    },
    methods: {
        // 查询初始化
        onInit() {
            this.pageInit.page = 1;
            this.selectInventory = [];
            this.cancelAllSelect = [];
            this.dishReviewSearch();
        },
        onShow() {
            this.$refs["cusDrawerRef"].show();
            this.dishReviewSearch();
            this.getDishAllSelect();
        },
        // 查询菜肴信息
        dishReviewSearch() {
            let params = {
                currentPage: this.pageInit.page,
                pageSize: this.pageInit.pageSize,
                dishName: this.dishSearchForm.dishName,
                similarStatus: this.dishSearchForm.similarStatus == -1 ? null : this.dishSearchForm.similarStatus,
            }
            mealReviewPage(params).then((res) => {
                if (res.retCode == 2000) {
                    let selectIncludes = [];
                    res.data.list = res.data.list.map((item) => {
                        if (this.selectInventory.includes(item.id)) selectIncludes.push(item.id);
                        return {
                            ...item,
                            _checked: this.selectInventory.includes(item.id),
                        }
                    });
                    this.dishReviewData = res.data.list;
                    this.dishReviewDataCopy = JSON.parse(JSON.stringify(res.data.list));
                    this.pageInit.pageTotal = res.data.total;
                    if (selectIncludes.length == this.dishReviewData.length) this.cancelAllSelect = selectIncludes;
                }
            });
        },
        // 选择菜肴匹配
        selectDishReview(id, detailList,) {
            mealReviewSelect({ id }).then((res) => {
                if (res.retCode == 2000) {
                    detailList.forEach((item) => {
                        item.used = item.id == id ? 1 : 0;
                    });
                    this.$Message.success("更换成功.");
                }
            });
        },
        // 打开编辑菜肴匹配
        editDishReview(detailIndex, index) {
            console.log('点击了')
            this.$set(this.dishReviewData[index].mealImportReviewDetailEntities[detailIndex], 'edit', true);
        },
        // 保存菜肴匹配数据
        saveDishReview(detailRow, detailIndex, index) {
            mealReviewEdit(detailRow).then((res) => {
                if (res.retCode == 2000) {
                    detailRow.edit = false;
                    this.$Message.success("修改成功!");
                    this.$set(this.dishReviewData[index].mealImportReviewDetailEntities, detailIndex, detailRow);
                    this.$set(this.dishReviewDataCopy[index].mealImportReviewDetailEntities, detailIndex, detailRow);
                    console.log('复制', this.dishReviewDataCopy[index].mealImportReviewDetailEntities[detailIndex])
                    this.dishReviewSearch();
                } else {
                    this.cancelDishReview(detailRow, detailIndex, index);
                    this.$Message.error('修改失败!');
                }
            });
            console.log('编辑菜肴匹配数据', detailRow);
        },
        // 取消菜肴匹配数据
        cancelDishReview(detailRow, detailIndex, index) {
            this.$set(this.dishReviewDataCopy[index].mealImportReviewDetailEntities[detailIndex], 'edit', false);
            this.$set(this.dishReviewData[index].mealImportReviewDetailEntities, detailIndex,
                JSON.parse(JSON.stringify(this.dishReviewDataCopy[index].mealImportReviewDetailEntities[detailIndex])));
            // this.dishReviewData[index].mealImportReviewDetailEntities[detailIndex].edit = false;
        },
        // 删除菜肴匹配
        deleteDishReview(id, row) {
            console.log('删除菜肴匹配', id, row);
            // 判断在只有一个菜肴匹配的情况下删除时删除整个菜肴
            if (row.mealImportReviewDetailEntities.length == 1) {
                this.dishReviewDeleteApi([row.id]).then((res) => {
                    console.log('promise', res)
                    if (res.retCode == 2000) {
                        let findIndex = this.selectInventory.findIndex((li) => li == row.id);
                        this.selectInventory.splice(findIndex, 1);
                        this.dishReviewSearch();
                    }
                })
            } else {
                this.dishReviewDeleteDetailApi(id);
            }
        },
        // 删除单个菜肴匹配
        dishReviewDeleteDetailApi(id) {
            mealReviewDeleteDetail({ id }).then((res) => {
                if (res.retCode == 2000) {
                    if (this.dishReviewData.length == 1 && this.dishReviewData[0].mealImportReviewDetailEntities.length == 1 && this.pageInit.page > 1) {
                        this.pageInit.page = this.pageInit.page - 1;
                    }
                    this.dishReviewSearch();
                    this.$Message.success('删除成功.');
                }
                else {
                    // this.$Message.error('删除失败.');
                }
            });
        },
        // 删除菜肴接口
        dishReviewDeleteApi(rowsId) {
            return new Promise((resolve) => {
                mealReviewDelete({ ids: rowsId }).then((res) => {
                    if (res.retCode == 2000) {
                        if (this.dishReviewData.length == 1 && this.pageInit.page > 1) {
                            this.pageInit.page = this.pageInit.page - 1;
                        }
                        this.$Message.success('删除成功.');
                        resolve(res);
                    } else {
                        // this.$Message.error('删除失败.');
                    }
                });
            });
        },
        // 移除表格中已勾选的选项
        removeSelection(rowsId) {
            rowsId.forEach((itemId) => {
                const rowIndex = this.dishReviewData.findIndex((row) => row.id == itemId);
                const selectionId = this.selectionList.map((item) => item.id);
                if (rowIndex !== -1) {
                    // 如果当前行被选中，则取消选中
                    if (selectionId.includes(this.dishReviewData[rowIndex].id)) {
                        // cusTableRef.value.tableRef.toggleRowSelection(dishReviewData.value[rowIndex], false)
                    }
                }
            });
            this.dishReviewSearch();
        },
        // 获取所有的数据选择框数据
        getDishAllSelect() {
            // 查询营养标签
            this.dishTargetApi();
            // 查询所有菜肴类型
            this.dishTypeApi();
            // 查询所有菜肴类别
            this.dishTypeSpecialtyApi();
            // 查询所有技法和口味
            this.dishAttributeValueApi();
        },
        // 查询营养标签
        dishTargetApi() {
            dishTarget().then((res) => {
                if (res.retCode == 2000) {
                    this.dishSelectData.dishTargetData = res.data;
                }
            });
        },
        // 查询所有菜肴类型
        dishTypeApi() {
            getDishListType().then((res) => {
                if (res.retCode == 2000) {
                    this.dishSelectData.dishTypeData = res.data;
                }
            });
        },
        // 查询所有菜肴类别
        dishTypeSpecialtyApi() {
            dishTypeSpecialty().then((res) => {
                if (res.retCode == 2000) {
                    this.dishSelectData.dishSpecialtyData = res.data;
                }
            });
        },
        // 查询所有技法和口味
        dishAttributeValueApi() {
            getDishAttributeValue({ ruleType: 0 }).then((res) => {
                if (res.retCode == 2000) {
                    this.dishSelectData.dishSkillData = res.data.filter((item) => item.ruleType == 1);
                    this.dishSelectData.dishTasteData = res.data.filter((item) => item.ruleType == 3);
                    console.log('技法', this.dishSelectData.dishSkillData);
                    console.log('口味', this.dishSelectData.dishTasteData);
                }
            });
        },
        // 关闭选择时清空
        onOpenSelect() {
            if (this.openSelect) {
                this.$refs.cusTableRef.tableDom();
                this.selectInventory = [];
                if (this.dishReviewColumns[0].type == 'selection') this.dishReviewColumns.shift();
            } else {
                this.dishReviewColumns.unshift({
                    type: 'selection',
                    width: 60,
                    align: 'center'
                });
            }
            this.openSelect = !this.openSelect;
        },
        // 删除整个菜肴触发
        selectDeleteDish() {
            this.$refs["cusModalRef"].show = true;
        },
        // 执行删除菜肴
        onConfrim() {
            // let ids = selectionList.value.map((item) => item.id);
            // console.log('需要删除的ID', ids);
            console.log('this.selectInventory', this.selectInventory)
            this.dishReviewDeleteApi(this.selectInventory).then((res) => {
                if (res.retCode == 2000) {
                    this.onInit();
                    this.$refs["cusModalRef"].show = false;
                }
            })
        },
        // 勾选数据
        changeSelect(v) {
            // this.selectionList = e;
            console.log('已经选中的', v);
            if (v.length == this.dishReviewData.length) {
                this.cancelAllSelect = v.map((item) => {
                    return item.id;
                })
                console.log('cc', this.cancelAllSelect);
            }
            v.forEach(item => {
                console.log('走了这里')
                if (this.selectInventory.findIndex((li) => li == item.id) == -1) this.selectInventory.push(item.id);
            });
            console.log('选中的id', this.selectInventory);
        },
        // 全选
        changeSelectAll(v) {
            console.log('勾选全部', v)
            v.forEach(item => {
                if (this.selectInventory.findIndex((li) => li == item.id) == -1) this.selectInventory.push(item.id);
            });
            console.log('所有选中的id', this.selectInventory);
        },
        // 取消某项
        onSelectCancel(v, row) {
            console.log('取消某项', v);
            console.log('11', row)
            let findIndex = this.selectInventory.findIndex((li) => li == row.id);
            console.log('下标', findIndex);
            this.selectInventory.splice(findIndex, 1);
            console.log('现有的id', this.selectInventory);
        },
        // 取消全选
        changeSelectAllCancel(v) {
            console.log('取消勾选全部', v)
            console.log('取消当前页所有', this.cancelAllSelect);
            this.cancelAllSelect.forEach(item => {
                this.selectInventory.splice(this.selectInventory.findIndex((li) => li == item), 1);
            });
        },
        // 关闭回调
        onClose() {
            console.log('触发关闭');
            this.cancelAllSelect = [];
            this.selectInventory = [];
            this.dishReviewDataCopy = [];
            this.dishReviewData = [];
            this.openSelect = false;
            this.pageInit = {
                page: 1,
                pageSize: 20,
                pageTotal: 0,
            };
            this.$parent.maskIndex = 1001;
            if (this.dishReviewColumns[0].type == 'selection') this.dishReviewColumns.shift();
        },
        confirmImport() {
            console.log('触发提交');
            examineMealReviewData().then(res => {
                if (res.retCode == 2000) {
                    this.returnMealPlanDataApi();
                } else if (res.retCode == 2888) {
                    let content = "";
                    if (res.data.result == -1) {
                        res.data.list.map((it) => {
                            content += `<p style="margin-top:5px">${it}</p>`;
                        });
                        this.$Modal.warning({
                            title: res.msg,
                            content: content,
                            width: "600",
                            okText: "确认",
                        });
                    }
                    // if (res.data.result == -2) {
                    //     res.data.dishList.map((it) => {
                    //         content += `<p style="margin-top:5px">${it}</p>`;
                    //     });
                    //     this.$Modal.confirm({
                    //         title: res.msg,
                    //         content: content,
                    //         width: "600",
                    //         okText: "确认覆盖",
                    //         cancelText: "跳过",
                    //         onOk: () => {
                    //             this.returnMealPlanDataApi();
                    //         },
                    //         onCancel: () => {
                    //             this.returnMealPlanDataApi();
                    //         },
                    //     });
                    // }
                }
            })
        },
        returnMealPlanDataApi() {
            returnMealPlanData().then((res) => {
                if (res.retCode == 2000) {
                    this.$refs["cusDrawerRef"].onCancel();
                    this.$Message.success("上传成功.");
                    this.$parent.intellectInit(res.data);
                }
            });
        },
    },
}
</script>
<style lang="scss" scoped>
::v-deep .ivu-table-tbody .ivu-table-cell {
    padding: 0 !important;
}

.dishFormBox {
    justify-content: flex-start !important;
}

.colStyle {
    padding: 12px 12px;
    // height: 48px;
    border-bottom: 1px solid #ebeef5;

    .disabledCol {
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .errReasonBox {
        width: 100%;
        justify-content: flex-start;
        white-space: nowrap;
        /* 防止文本换行 */
        overflow: hidden;
        /* 隐藏超出容器的部分 */
        text-overflow: ellipsis;
        /* 用省略号表示被裁剪的文本 */
    }
}

.colStyle:last-child {
    border-bottom: none;
}

.colOperStyle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px 7px 12px;
    border-bottom: 1px solid #ebeef5;
}

.colOperStyle:last-child {
    border-bottom: none;
}

.editOperStyle {
    padding: 12px 12px 11px 12px;
}

.errorDialogBox {
    display: flex;
    align-items: center;
    color: #cb0000;
    font-size: 14px;
    margin-top: 10px;
}
</style>